package com.haircut.controller;

import cn.hutool.core.bean.BeanUtil;
import com.haircut.base.Result;
import com.haircut.mapper.HaircutUserRecharge;
import com.haircut.model.dto.UserRechargeDTO;
import com.haircut.security.util.SecurityUtils;
import com.haircut.service.HaircutUserRechargeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/user/chagre")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "用户消费")
public class ChargeController {

    private final HaircutUserRechargeService rechargeService;

    @Operation(summary = "充值记录")
    @GetMapping("/list")
    public Result<List<UserRechargeDTO>> list() {
        Long userId = SecurityUtils.getUser().getUserId();
        List<HaircutUserRecharge> list = rechargeService.getRecharge(userId,null);
        List<UserRechargeDTO> userRechargeDTOS = BeanUtil.copyToList(list, UserRechargeDTO.class);
        return Result.success(userRechargeDTOS);
    }

}
